<template>
  <el-dialog
    :title="'查看举报详情'"
    :visible="visible"
    width="760px"
    :destroy-on-close="true"
    :lock-scroll="false"
    @update:visible="updateVisible"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-form-item label="举报内容类型" class="custom-form-item">
        <span v-html="typeArr[form.type]"></span>
      </el-form-item>

      <el-form-item label="举报内容详情:" class="custom-form-item">
        <!-- <span v-text="form.content"></span> -->
        <el-link
          type="primary"
          icon="el-icon-open"
          @click="
            openReportInfo({
              type: form.type,
              target_id: form.target_id
            })
          "
          >查看举报内容详情
        </el-link>
      </el-form-item>
      <el-form-item label="举报人昵称:" class="custom-form-item">
        <span v-text="form.member_nickname"></span>
      </el-form-item>
      <el-form-item label="举报人ID:" class="custom-form-item">
        <span v-text="form.member_id"></span>
      </el-form-item>
      <el-form-item label="举报人原因:" class="custom-form-item">
        <span v-text="form.reason"></span>
      </el-form-item>
      <el-form-item label="举报处理状态:" class="custom-form-item">
        <span v-text="statusArr[initStatus]"></span>
      </el-form-item>
      <el-form-item label="举报时间:" class="custom-form-item">
        <span v-text="this.$util.toDateString(form.create_time)"></span>
      </el-form-item>

      <span style="font-size: 25px">举报处理</span><br /><br />

      <div></div>
      <el-form-item label="被举报人昵称:">
        <el-input
          :disabled="true"
          v-model="form.target_member_nickname"
          controls-position="right"
          class="ele-fluid ele-text-left"
        />
      </el-form-item>

      <el-form-item label="被举报人id:" prop="target_member_id">
        <el-input-number
          :disabled="true"
          v-model="form.target_member_id"
          controls-position="right"
          class="ele-fluid ele-text-left"
        />
      </el-form-item>

      <el-form-item label="核实举报内容：" prop="status">
        <el-radio-group :disabled="!canChange" v-model="form.status">
          <el-radio :label="1">属实</el-radio>
          <el-radio :label="2">不属实</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="是否处罚：" prop="deal_status">
        <el-radio-group :disabled="!canChange" v-model="form.deal_status">
          <el-radio :label="1">处罚</el-radio>
          <el-radio :label="0">不处罚</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item
        v-show="form.deal_status == 1"
        label="处罚规则"
        prop="banRules"
      >
        <el-select
          clearable
          :disabled="!canChange"
          v-model="form.ban_rule_id"
          placeholder="请选择处罚规则"
          class="ele-fluid"
        >
          <el-option
            v-for="item in banRules"
            :key="item.id"
            :label="item.title"
            :value="item.id"
          />
        </el-select>
      </el-form-item>

      <el-form-item v-show="form.deal_status == 1">
        <!-- <el-checkbox :disabled="!canChange" v-model="form.is_del_content"
          >一并删除举报内容</el-checkbox
        > -->
        <el-checkbox :disabled="!canChange" @change=changeDelete>一并删除举报内容</el-checkbox>
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button @click="updateVisible(false)">取消</el-button>
      <el-button type="primary" @click="save">保存 </el-button>
    </div>
  </el-dialog>
</template>

<script>
import { statusArr, typeArr } from "./report";

export default {
  name: "ReportDetail",
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object,
    banRules: []
  },
  data() {
    return {
      // 表单数据
      form: Object,
      // 表单验证规则
      rules: {},
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false,
      statusArr,
      typeArr,
      initStatus: null,
      canChange: false,
      is_del_content: Number,
      // showReportInfo: false,
      // current: null,
      deleteInfo:true,
      reportInfoData: {}
    };
  },
  watch: {
    data() {
      if (this.data) {
        this.form = Object.assign({}, this.data);
        this.isUpdate = true;
        this.initStatus = this.data.status;
        this.canChange = this.data.status == 0;
        this.form.is_del_content = this.form.is_del_content ? true : false;
      } else {
        this.form = {};
        this.isUpdate = false;
      }
    }
  },
  methods: {
    /* 刷新表格 */
    reload() {
      this.$refs.table.reload({ where: this.where });
    },
    /* 保存编辑 */
    save() {
      if (this.data.ban_status) {
        this.$message.error("需等待用户上次处罚结束");
        return;
      }
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.$http
            .post("/boxReport/handleReport", this.form)
            .then(res => {
              if (res.data.code === 0) {
                this.$message.success(res.data.msg);
                if (!this.isUpdate) {
                  this.form = {};
                }
                this.updateVisible(false);
                this.$emit("done");
              } else {
                this.$message.error(res.data.msg);
              }
            })
            .catch(e => {
              this.$message.error(e.message);
            });
        } else {
          return false;
        }
      });
    },
    changeDelete(e){
      if(e === true){
        this.form.is_del_content = true
      }else{
        this.form.is_del_content = false
      }
    },
    /* 更新visible */
    updateVisible(value) {
      this.$emit("update:visible", value);
    },
    /* 显示举报内容详情 */
    openReportInfo(row) {
      this.$http
        .get("/boxArticle/getArticleOrCommentInfo", { params: row })
        .then(res => {
          if (res.data.code === 0) {
            this.$alert(res.data.data.content, res.data.data.title, {
              showConfirmButton: false,
              dangerouslyUseHTMLString: true,
              customClass: "article-checkList",
              center: true
              // callback: action => {
              //   // 在关闭（点击确定按钮）时触发的回调函数
              //   console.log("关闭了 alert");
              //   // 在这里执行你想要的逻辑
              // }
            });
          } else {
            this.$message.error(res.data.msg || "获取数据失败");
          }
        })
        .catch(e => {
          this.$message.error(e.message);
        });
    }
  }
};
</script>

<style scoped>
.custom-form-item {
  margin-bottom: 5px; /* Adjust the margin as needed */
}
</style>
<style>
.article-checkList {
  padding-bottom: 15px;
  width: 1000px;
  max-height: 800px;
  min-height: 500px;
  overflow: scroll;
}
.article-checkList img {
  max-width: 800px;
}
</style>
